<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use backend\assets\FancyBoxAsset;
FancyBoxAsset::register($this);

/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessPigFile */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Business Pig Files', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>


<section class="wrapper site-min-height">
    <!-- page start-->
    <section class="panel">
        <header class="panel-heading">
              <?= Html::a('返回','javascript:history.back(-1)'); ?>  <?= Html::encode($this->title) ?>
        </header>
        <div class="panel-body">
            <div class="adv-table editable-table ">

                <div class="business-pig-file-view">

                    <p>
                        <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
                        <?= Html::a('删除', ['delete', 'id' => $model->id], [
                            'class' => 'btn btn-danger',
                            'data' => [
                                'confirm' => '您确定删除此项吗?',
                                'method' => 'post',
                            ],
                        ]) ?>
                    </p>

                    <?= DetailView::widget([
                        'model' => $model,
                        'template' => '<tr><th style="width:10%">{label}</th><td>{value}</td></tr>',
                        'attributes' => [
                            'name',
                            'no',
                            'father',
                            'mathor',
                            [
                                'attribute' => 'varietyname.title',
                                'label' => '品种'
                            ],
                            [
                                'attribute' => 'constract.name',
                                'label' => '合同'
                            ],
                            [
                                'format' => 'raw',
                                'attribute' => 'matherphoto',
                                'value' => function($model){
                                    $img = \common\components\Upload::checkGetUrl($model->matherphoto);
                                    return "<a class='fancybox' rel='matherphoto' href='{$img}'>".Html::img($img,['width'=>150]).'</a>';
                                }
                            ],
                            [
                                'format' => 'raw',
                                'attribute' => 'fatherphoto',
                                'value' => function($model){
                                    $img = \common\components\Upload::checkGetUrl($model->fatherphoto);
                                    return "<a class='fancybox' rel='fatherphoto' href='{$img}'>".Html::img($img,['width'=>150]).'</a>';
                                }
                            ],
                            [
                                'attribute'=>'pigs',
                                'format'=>'raw',
                                'value'=>function($model){
                                    $html = '';
                                    foreach ($model->pigs as $key => $row){
                                        $html .= Html::label($row->no,'',['class'=>'btn btn-default btn-xs','style'=>'margin-right:10px;']);
                                    }
                                    return $html;
                                }
                            ],
                        ],
                    ]) ?>

                </div>
            </div>
        </div>
    </section>
</section>

<script>
    <?php $this->beginBlock('js_end') ?>
    //点击预览图片
    $('.fancybox').fancybox({
        'titlePosition' : 'over',
        'cyclic'        : true,
        'height':500
    });
    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>

</script>